#include "../Basics/BasicStruct.cpp"

// 层次遍历孩子兄弟链表

queue<TreeNode*> Q;

void LayerOrder(TreeNode* bt) {
    if (bt == NULL) {
        return;
    }
    initTreeQueue(Q);
    enterTreeQueue(Q,bt);
    while(!EmptyTreeQueue(Q)) {
        TreeNode * p = deleteTreeQueue(Q);
        printf("%d ",p->data);
        if (p->leftChild != NULL) {
            enterTreeQueue(Q,p->leftChild);
        }
        while(p != NULL) {
            p = p->rightChild;
            if (p != NULL) {
                if (p->leftChild != NULL) {
                    enterTreeQueue(Q,p->leftChild);
                }
                printf("%d ",p->data);
            }
        }
    }
}


/*
  *       5
  *      / \
  *     1   7
  *        / \
  *       6   8
  * */

int main() {
    Tree tree = CreateTree();
    LayerOrder(tree);
}